package com.test.bean;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.aop.MethodBeforeAdvice;

import java.lang.reflect.Method;

public class CompanyAspect {
    public void doBefore(JoinPoint joinPoint) {
        System.out.println("run 方法正在被doBefore增强。");


    }

    public void doAfter(JoinPoint joinPoint) {
        System.out.println("run 方法正在被doAfter增强。" + joinPoint.getSignature().getName());
        Object[] objects = joinPoint.getArgs();
        for (Object obj : objects) {
            System.out.println(obj.toString());
        }

    }

    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {


        System.out.println("run 方法正在被doAround前置增强。");

        Object obj = joinPoint.proceed(new Object[]{"cccc","dddddddddddd"});


        System.out.println("run 方法正在被doAround后置增强。");

        return obj;
    }

    public void  doAfterRetruning(JoinPoint joinPoint,Object result){
        System.out.println("run 方法正在被doAfterRetruning增强。"+result);
    }

    public void doAfterThrowing(JoinPoint joinPoint,Throwable ex){
        ex.printStackTrace();
        System.out.println("run 方法正在被doAfterThrowing增强。");
    }

    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("run 方法正在被doBefore增强。");
    }
}
